/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Acceso;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author HnosRodriguez
 */
public class AccesoSpss {
    private Conexion conex;
    private ResultSet consultaSelect;
    
    public AccesoSpss(){
        this.conex = new Conexion();
    }
    public void insertarRegistro(String insert){
        try {
            
                this.conex.realizarInsertUpdateDelete(insert);
                System.out.println("Se inserto con exito");
                this.conex.getStmt().close();
                
        } catch (SQLException ex) {
            System.out.println("No se pudo cerrar el statament: "+ex.getMessage());
        }
    }
    
    public int obtenerIdEncuestaInsertada(String consulta){                
        try {
              consultaSelect = this.getConex().realizarConsulta(consulta);
             
                  while (consultaSelect.next()) {
                      return Integer.parseInt(consultaSelect.getString(1));
                  }
              
          return 0;
          
        } catch (SQLException ex) {            
            System.out.println(ex.getMessage());
            return 0;
        }
      finally{
            try {

                this.getConex().getStmt().close();
                
            } catch (SQLException ex) {
                System.out.println("No se pudo cerrar el statament: "+ex.getMessage());
            }
        }
    }

    public Conexion getConex() {
        return conex;
    }

    public void setConex(Conexion conex) {
        this.conex = conex;
    }

    public ResultSet getConsultaSelect() {
        return consultaSelect;
    }

    public void setConsultaSelect(ResultSet consultaSelect) {
        this.consultaSelect = consultaSelect;
    }
        
}
